package com.zaizai.controller;

import java.util.List;

import com.zaizai.aop.AutoLog;
import com.zaizai.domain.AjaxResult;
import com.zaizai.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zaizai.domain.Department;
import com.zaizai.service.IDepartmentService;

import static com.zaizai.domain.AjaxResult.success;


/**
 * 部门Controller
 *
 * @author zaiZai
 * @date 2024-10-22
 */

@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController {
    @Autowired
    private IDepartmentService departmentService;

/**
 * 查询部门列表
 */

@GetMapping("/list")
    public TableDataInfo list(Department department) {
        startPage();
        List<Department> list = departmentService.selectDepartmentList(department);
        return getDataTable(list);
    }

    /**
     * 获取部门详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(departmentService.selectDepartmentById(id));
    }

    /**
     * 新增部门
     */
    @PostMapping
    @AutoLog("新增部门信息")
    public AjaxResult add(@RequestBody Department department) {
        return success(departmentService.insertDepartment(department));
    }

    /**
     * 修改部门
     */
    @PutMapping
    @AutoLog("修改部门信息")
    public AjaxResult edit(@RequestBody Department department) {
        return success(departmentService.updateDepartment(department));
    }

    /**
     * 删除部门
     */

    @DeleteMapping("/{ids}")
    @AutoLog("删除部门信息")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return success(departmentService.deleteDepartmentByIds(ids));
    }
}
